package com.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dao.DictionaryDAO;
import com.pojo.Dictionary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DictionaryService extends ServiceImpl<DictionaryDAO, Dictionary> {

    @Autowired
    private DictionaryDAO dictionaryDAO;

    /**
     * 根据字典类型和字典CODE获取字典信息
     * @param type
     * @param code
     * @return
     */
    public Dictionary getDicByCode (String type,String code){
        List<Dictionary> dicList = dictionaryDAO.selectList(new QueryWrapper<Dictionary>().eq("code",code).eq("type",type));
        if (dicList.size() >0) {
            return dicList.get(0);
        }
        return null;
    }

    /**
     * 获取字典ID列表
     * @return
     */
    public List<String> getDicIdList () {
        return dictionaryDAO.selectDicId();
    }

    /**
     * 获取物业字典ID列表
     * @return
     */
    @DS("slave")
    public List<String> getWyDicIdList () {
        return dictionaryDAO.selectDicId();
    }

    /**
     * 根据字典ID获取物业字典列表
     * @param idList
     * @return
     */
    @DS("slave")
    public List<Dictionary> getWyDicList (List<String> idList) {
        return dictionaryDAO.selectBatchIds(idList);
    }
}
